//处理拖动效果
var beginMoving = false;

function MouseDownToMove (obj)
{
   obj.style.zIndex = 1;
   obj.mouseDownY = event.clientY;
   obj.mouseDownX = event.clientX;
   beginMoving = true;
   obj.setCapture ();
}

function MouseMoveToMove (obj)
{
   if(!beginMoving) return false;

for (i = 0; i < obj.cells.length; i ++)
    obj.cells [i].style.filter = "alpha(opacity = 70)";
   obj.style.top = (event.clientY - obj.mouseDownY);
   obj.style.left = (event.clientX - obj.mouseDownX);
}

function MouseUpToMove (obj)
{
   if (!beginMoving) return false;

   obj.releaseCapture ();
   obj.style.top = 0;
   obj.style.left = 0;
   obj.style.zIndex = 0;
   beginMoving = false;
   var objHeight = obj.clientHeight;

   var tempTop = event.clientY - obj.mouseDownY;
   var tempRowIndex = (tempTop - tempTop % objHeight) / objHeight;


   if (tempRowIndex + obj.rowIndex < 0 )
       tempRowIndex = -1;
   else
       tempRowIndex = tempRowIndex+obj.rowIndex;
   //0是表头，-1是超过表头，会跳到表尾，所以置为1，跳到第一行
   if(tempRowIndex<=0)
   		tempRowIndex=1;
   if (tempRowIndex >= obj.parentElement.rows.length - 1)
	   tempRowIndex = obj.parentElement.rows.length - 1;

	for (i = 0; i < obj.cells.length; i ++)
		obj.cells [i].style.filter = "alpha(opacity = 100)";
   obj.parentElement.moveRow(obj.rowIndex, tempRowIndex);
}
